//
//  CommonUtils.m
//  Xinzhoulvye
//
//  Created by Kevin Su on 15/2/12.
//  Copyright (c) 2015年 com.threeti.yuetao. All rights reserved.
//

#import "CommonUtils.h"
#import "SVProgressHUD.h"

@implementation CommonUtils

+ (bool)checkDevice:(NSString*)name
{
    NSString* deviceType = [UIDevice currentDevice].model;
    NSLog(@"deviceType = %@", deviceType);
    
    NSRange range = [deviceType rangeOfString:name];
    return range.location != NSNotFound;
}

+ (void)telWithMobilePhone:(NSString *)mobilePhone{
    
    //拨打电话
    NSString *urlString = [NSString stringWithFormat:@"tel:%@",mobilePhone];
    NSURL *url = [NSURL URLWithString:urlString];
    
    //判断设备型号
    NSString *  nsStrIpod=@"iPod";
    NSString *  nsStrIpad=@"iPad";
    bool  bIsiPod=false;
    bool  bIsiPad=false;
    bIsiPod=[self checkDevice:nsStrIpod];
    bIsiPad=[self checkDevice:nsStrIpad];
    if(bIsiPad || bIsiPod){
        
        [SVProgressHUD showErrorWithStatus:@"该设备不支持电话功能"];
        return;
    }
    
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        UIWebView *callWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
        [callWebView loadRequest:[NSURLRequest requestWithURL:url]];
        
    }else{
        [SVProgressHUD showErrorWithStatus:@"该设备不支持电话功能"];
    }
}

@end
